﻿@using ZX.Tools
@using ZX.Model
@model AttendanceTime
@{
    ViewBag.Title = "考勤设置-指效";
    Sys_UserModel user = ViewBag.User;
    List<Dictionary> listApplyMoneyUnit = ViewBag.ListApplyMoneyUnit ?? new List<Dictionary>();
}
<link href="~/Static/styles/bootstrap.min.css" rel="stylesheet" />
<link href="~/Static/js/layui/css/layui.css" rel="stylesheet" />
<link href="~/Static/js/layer/need/layer.css" rel="stylesheet" />
<link href="~/Static/js/Validform/css/style.css" rel="stylesheet" />
<link href="~/Static/js/datetimepicker/datetimepicker.min.css" rel="stylesheet" />
<script src="/Static/js/jquery/jquery-1.11.1.min.js"></script>
<script src="~/Static/js/admin.min.js"></script>
<script src="~/Static/js/jquery/form/min.js"></script>
<script src="~/Static/js/Validform/js/Validform_v5.3.2_min.js"></script>
<script src="~/Static/js/layer/layer.js"></script>
<script src="~/Static/js/layer/layer.tools.js"></script>
<script src="~/Static/js/layui/layui.js"></script>
<script src="~/Static/js/ajaxfileupload.js"></script>
<script src="~/Static/res/My97DatePicker/WdatePicker.js"></script>
<script src="~/Static/js/datetimepicker/datetimepicker.min.js"></script>
<style>
    .top-navbar-index {
        position: inherit;
        width: 100%;
        margin-bottom: 0;
    }

    .with-menu {
        padding: 20px;
    }

    .cur {
        float: left;
    }
</style>
@Html.Raw(ViewBag.SysAdminMainNavbar)
<div>
    <div class='panel'>
        <div class='panel-heading'><strong><i class='icon-building'></i>考勤设置单</strong></div>
        <div class='panel-body'>
            <form action="/AttendanceTime/SaveData" method="post" class="form" id="formMy_Work">
                <input type="hidden" name="Id" value="@Model.Id" />
                <table class='table table-bordered' style="border: 1px solid #ddd;">
                    <tr>
                        <th class="text-center w-200px">考勤月份</th>
                        <td class="text-center w-600px">
                            <input type="text" id="Date" name="Date" placeholder="考勤月份（格式：2018年8月）" class="form-control" autocomplete="off" value="@Model.Date" nullmsg="请输入考勤月份">
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center w-200px">上午上班时间</th>
                        <td class="text-center w-600px">
                            <div>
                                <input type="text" class='form-control form-date' id="AmStartTime" name="AmStartTime" placeholder="时间" value="@Model.AmStartTime.ToDateFormat("HH:00")" onfocus="WdatePicker({dateFmt:'HH:mm'})" style="width:120px; float:left;" onblur="getDateDiff()" />
                                <span>至</span>
                                <input type="text" class='form-control form-date' id="AmEndTime" name="AmEndTime" placeholder="时间" value="@Model.AmEndTime.ToDateFormat("HH:00")" onfocus="WdatePicker({dateFmt:'HH:mm'})" style="width:120px; float:right" onblur="getDateDiff()" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center w-200px">下午上班时间</th>
                        <td class="text-center w-600px">
                            <div>
                                <input type="text" class='form-control form-date' id="PmStartTime" name="PmStartTime" placeholder="时间" value="@Model.PmStartTime.ToDateFormat("HH:00")" onfocus="WdatePicker({dateFmt:'HH:mm'})" style="width:120px; float:left;" onblur="getDateDiff()" />
                                <span>至</span>
                                <input type="text" class='form-control form-date' id="PmEndTime" name="PmEndTime" placeholder="时间" value="@Model.PmEndTime.ToDateFormat("HH:00")" onfocus="WdatePicker({dateFmt:'HH:mm'})" style="width:120px;float:right;" onblur="getDateDiff()" />
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <th class="text-center w-200px">单双休</th>
                        <td class="text-center w-600px">
                            <select name="WorkDay" id="WorkDay" class="form-control" style="width:80px;">
                                @{
                                    foreach (var itemUnit in listApplyMoneyUnit)
                                    {
                                        if (Model.WorkDay.IsNotNullOrEmpty() && Model.WorkDay.Equals(itemUnit.Name))
                                        {
                                            <option selected value="@itemUnit.Name">@itemUnit.Name</option>
                                        }
                                        else
                                        {
                                            <option value="@itemUnit.Name">@itemUnit.Name</option>
                                        }
                                    }
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center w-200px">每月应出勤天数</th>
                        <td class="text-center w-600px">
                            <input type="text" id="WorkDays" name="WorkDays" placeholder="出勤天数" class="form-control" autocomplete="off" value="@Model.WorkDays" nullmsg="请输入每月出勤天数">
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center w-200px">适用对象</th>
                        <td class="text-center w-600px">
                            <input type="text" id="ApplicableObject" name="ApplicableObject" placeholder="适用对象（全体员工）" class="form-control" autocomplete="off" value="@Model.ApplicableObject" nullmsg="请输入适用对象">
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <td colspan='5'>
                            <a href='javascript:;' class='btn btn-primary' onclick='saveData()'>提交</a>
                            &nbsp;&nbsp;
                            <a href='javascript:;' class='btn btn-back' onclick='goBack()'>返回</a>
                            <span id="spmsg"></span>
                        </td>
                    </tr>
                </table>
                <input type="hidden" id="submitMsg" value="" />
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        $("#formMy_Work").Validform({
            tiptype: function (msg, o, cssctl) {
                var objtip = $("#spmsg");
                cssctl(objtip, o.type);
                objtip.text(msg);
            },
            callback: function (form) {
                win.showLoading("正在保存...");

                $("#formMy_Work").ajaxSubmit(function (data) {
                    if (data.Code == 300) {
                        win.alert(data.Message);
                    } else if (data.Code == 200) {
                        win.success("保存成功", function () {
                            goBack();
                        }, 1000);
                    }
                });
                return false;
            }
        });
    });

    function saveData() {
        $("#submitMsg").val("提交成功");
        $("#formMy_Work").submit();
    }

    function goBack() {
        window.history.go(-1);
    }
    function getDateDiff() {
        if ($("#StartTime").val() != "" && $("#EndTime").val() != "") {
            var edate = new Date($("#EndTime").val());
            var mm = edate.getMonth() + 1;
            var dd = $.trim($("#stime").val()) == "" || $.trim($("#etime").val()) == "" ? edate.getDate() + 1 : edate.getDate();
            var etime = edate.getFullYear() + "-" + mm + "-" + dd;
            var btime = $("#StartTime").val() + ($.trim($("#stime").val()) != "" ? " " + $("#stime").val() + ":00" : "");
            etime = etime + ($.trim($("#etime").val()) != "" ? " " + $("#etime").val() + ":00" : "");
            var hh = $.admin.getDateDiff(btime, etime, "hh");
            dd = parseInt(hh / 24);
            hh = hh % 24;
            if (hh != 0) {
                if (dd > 0) {
                    $("#iday").html("共 " + dd + " 天" + hh + "小时");
                } else {
                    $("#iday").html("共 " + hh + "小时");
                }
            } else {
                $("#iday").html("共 " + dd + " 天");
            }
        }
    }
</script>
